import { Map } from 'immutable';
import * as types from './constans';
// 0循环播放  1随机播放  2单曲循环
function getItem(name) {
    return JSON.parse(localStorage.getItem(name) || '[]')
}
let list = getItem('play_list');
const defaultState = Map({
    playList: list,
    curSongIdx: 0,
    curSong: {},
    addSongDetail: {},
    firstLoad: true,
    lyrList: [],
    playSequence: 0,
    curLyrIdx: 0,
    playListCount: list.length,
    hotComments: [],
    curCommentTotal: 0,
})

const reducer = (state = defaultState, action) => {
    switch (action.type) {
        case types.CHANGE_CUR_SONG:
            console.log('cursong', action.curSong);
            return state.set('curSong', action.curSong)
        case types.CHANGE_PLAY_LIST:
            window.localStorage.setItem('play_list', JSON.stringify(action.playList))
            return state.set('playList', action.playList);
        case types.CHANGE_PLAY_SEQUENCE:
            return state.set('playSequence', action.sequence)
        case types.CHANGE_CUR_SONG_IDX:
            return state.set('curSongIdx', action.i);
        case types.CHANGE_LYR_LIST:
            return state.set('lyrList', action.lyrList);
        case types.CHANGE_CUR_LYR_IDX:
            return state.set('curLyrIdx', action.i)
        case types.CHANGE_FIRST_LOAD:
            return state.set('firstLoad', action.isLoad);
        case types.CHANGE_ADD_SONG_DETAIL:
            return state.set('addSongDetail', action.addSongDetail)
        case types.CHANGE_PLAY_LIST_COUNT:
            return state.set('playListCount', action.count)
        case types.CHANGE_HOT_COMMENT:
            return state.set('hotComments', action.hotComments);
        case types.CHANGE_CUR_COMMENT_TOTAL:
            return state.set('curCommentTotal', action.total)
        default:
            return state
    }
}
export default reducer